package com.example.controller;

import com.example.entity.GoodsLanguagesRolling;
import com.example.entity.User;
import com.example.mapper.GoodsLanguagesRollingMapper;
import com.example.service.UserService;
import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author:0xOO
 * @Date: 2018/9/26 0026
 * @Time: 14:42
 */

@RestController
@RequestMapping("/testBoot")
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private GoodsLanguagesRollingMapper repository;

    @RequestMapping("getUser/{id}")
    public String GetUser(@PathVariable int id){
        return userService.Sel(id).toString();
    }
    
    @RequestMapping("health/status")
    public String status(){
    	// 构造list
    			/*List<GoodsLanguagesRolling> list = repository.selectByList();*/
    			/*for(int i=0;i<list.size();i++) {
    				GoodsLanguagesRolling goodsLanguagesRolling = list.get(i);
    				goodsLanguagesRolling.setGoodsName("batshUpdateTempGoodsName="+i);
    				goodsLanguagesRolling.setGoodsDesc("batshUpdateTempGoodsDesc="+i);
    				goodsLanguagesRolling.setHasTranslate(0);
    			}*/
    			
    			
    			List<GoodsLanguagesRolling> listUpdate = new ArrayList<>();
    			/*listUpdate.add(list.get(0));*/
    			List<List<GoodsLanguagesRolling>> partitionList = Lists.partition(listUpdate, 5000);
    	        for (List<GoodsLanguagesRolling> codeList : partitionList) {
    	            try {
    	            	repository.updateBatchTemp(codeList);
    	            }catch (Exception e){
    	                throw e;
    	            }
    	        }
		
        return "OK";
    }
}
